package portal.web.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import portal.entidades.Configuracion;
import portal.web.delegate.IPortalWebDelegate;
import portal.web.delegate.PortalWebDelegate;

/**
 * Handling adding new data
 */
@WebServlet("/Configuracion/ConfiguracionAdd")
public class ConfiguracionAdd extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ConfiguracionAdd() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Long id = new Long(request.getParameter("id"));
		String valor = request.getParameter("valor");
		String tipoServicio = request.getParameter("tipoServicio");
		Long nroGrupo = new Long(request.getParameter("nroGrupo"));

		Configuracion configuracion = new Configuracion();
		
		IPortalWebDelegate app = PortalWebDelegate.getInstanace();
		try {

			configuracion.setId(id);
			configuracion.setValor(valor);
			configuracion.setNumeroGrupo(nroGrupo);
			configuracion.setTipoServicio(tipoServicio);
			
			// TODO: implementar metodo de backend
			app.agregarConfiguracion(configuracion);

			response.getWriter().print(configuracion.getId().toString());

		} catch (Exception e) {
			response.getWriter()
			.print("Error - la configuracion no fue creada");
		}

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
}
